package mil.af.amc.adpetracker.web.actions.struts2.itemModel;

import com.opensymphony.xwork2.ActionSupport;
import com.opensymphony.xwork2.ModelDriven;
import com.opensymphony.xwork2.Preparable;
import mil.af.amc.adpetracker.model.ItemModel;
import mil.af.amc.adpetracker.service.ItemModelService;
import org.apache.struts2.convention.annotation.Action;
import org.apache.struts2.convention.annotation.Result;
import org.springframework.beans.factory.annotation.Autowired;

import java.util.List;

/**
 * @author Jason Ferguson
 */
public class ItemModelAction extends ActionSupport implements ModelDriven<ItemModel>, Preparable {

    @Autowired
    private ItemModelService itemModelService;

    private List<ItemModel> itemModelList;

    // ModelDriven implementation
    private ItemModel model;

    public ItemModel getModel() {
        return model;
    }

    // Preparable implementation
    public void prepare() {

    }

    public void prepareExecute() {
        itemModelList = itemModelService.getAll();
    }

    /**
     * Return the "list" view of ItemModels
     *
     * @return
     * @throws Exception
     */
    @Action(value = "list", results = {
            @Result(name = "success", location = "/WEB-INF/struts2/itemModel/list.jsp")
    })
    public String execute() throws Exception {
        return SUCCESS;
    }

    /**
     * Return the create ItemModel view
     *
     * @return
     * @throws Exception
     */
    @Action(value = "viewCreate", results = {
            @Result(name="success", location = "/WEB-INF/struts2/itemModel/create.jsp")
    })
    public String viewCreate() throws Exception {
        throw new UnsupportedOperationException();
    }

    /**
     * Create an ItemModel
     *
     * @return
     * @throws Exception
     */
    @Action(value="create", results = {
            @Result(name = "success", location = "/WEB-INF/struts2/itemModel/list.jsp"),
            @Result(name = "input", location = "/WEB-INF/struts2/itemModel/create.jsp")
    })
    public String create()  throws Exception {
        throw new UnsupportedOperationException();
    }

    /**
     * Return the Edit ItemModel view
     *
     * @return
     * @throws Exception
     */
    @Action(value="viewEdit", results = {
            @Result(name = "success", location = "/WEB-INF/struts2/itemModel/edit.jsp")
    })
    public String viewEdit() throws Exception {
        throw new UnsupportedOperationException();
    }

    /**
     * Edit an ItemModel
     * @return
     * @throws Exception
     */
    @Action(value = "edit", results = {
            @Result(name = "success", location = "/WEB-INF/struts2/itemModel/list.jsp"),
            @Result(name = "input", location = "/WEB-INF/struts2/itemModel/edit.jsp")
    })
    public String edit() throws Exception {
        throw new UnsupportedOperationException();
    }

    /**
     * Return a JSON list of ItemModels for a given Manufacturer
     * @return
     * @throws Exception
     */
    @Action(value="getByManufacturer", results = {
            @Result(name = "success", type = "json")
    })
    public String getItemModelsByManufacturer() throws Exception {
        throw new UnsupportedOperationException();
    }

    /**
     * Return a JSON list of ItemModels for a given EquipmentType
     *
     * @return
     * @throws Exception
     */
    @Action(value="getByEquipmentType", results = {
            @Result(name="success", type = "json")
    })
    public String getItemModelsByEquipmentType() throws Exception {
        throw new UnsupportedOperationException();
    }
}
